window.onload = function () {
	var imgBox = document.getElementById('imgBox');
	var imgList = imgBox.getElementsByTagName('img');
	var i = 0;
	var imgWid = imgList[0].offsetWidth;
	var allWid = imgWid * (imgList.length - 1);
	var point = document.getElementsByClassName('point');
	var time;
	// 轮播 Wu-J
	function carousel() {
		i++;
		if(i >= 0 && i < 1200) {
			point[0].style.background = "#fff";
			point[1].style.background = "gray";
			point[2].style.background = "gray";

		} else if(i >= 1200 && i < 2400) {
			point[0].style.background = "gray";
			point[1].style.background = "#fff";
			point[2].style.background = "gray";
		} else if(i >= 2400 && i < 3600) {
			point[0].style.background = "gray";
			point[1].style.background = "gray";
			point[2].style.background = "#fff";
		}else{
			point[0].style.background = "#fff";
			point[1].style.background = "gray";
			point[2].style.background = "gray";
		}

		if(i % imgWid == 0) {
			imgBox.style.marginLeft = -i + "px";
			time = setTimeout(carousel, 3000);
		} else{
			imgBox.style.marginLeft = -i + "px";
			time = setTimeout(carousel, 5);
		}
		if(i == allWid) {
			i = 0;
		}
    }
	carousel();
	// 点击 Wu-J
	for(var x = 0; x < point.length; x++) {
		point[x].x = x;
		point[x].onclick = function() {
			clearTimeout(time);
			i = this.x * 1200;
			for (var j = 0; j < point.length; j++) {
				point[j].style.background = "gray";
			}
			this.style.background = "#fff";
			imgBox.style.marginLeft = -i + "px";
			time = setTimeout(carousel, 3000);
		}
	}
	// 顶部、底部导航 跟随窗口 Gao-J
	window.addEventListener("scroll",scrollShow,false);
	function scrollShow() {
		var scrolltop =  document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
		console.log(scrolltop);
		headNavShow(scrolltop,0,1500);footNavShow(scrolltop,1000);
    }
    function headNavShow(a,b,c) {
        var headNav = document.getElementById("nav-background");
        if (a >= b && a < c) {
            headNav.style.display = "block";
            headNav.style.position = "fixed";
            headNav.style.top = "0";
        }else if(a >= c){ headNav.style.display = "none";
        }else{ headNav.style.position = "relative"}
    }
    function footNavShow(a,c) {
        var footNav = document.getElementById("footer-nav-container");
        if (a < c) {
            footNav.style.position = "fixed";
            footNav.style.buttom = "0";
        }else{ footNav.style.position = "relative"}
    }
    footNavShow(0,1);
}
